#!/usr/local/bin/perl5
use 5.010;
use warnings;

my $names='Fred or Barney';
if($names=~m/(?<name1>\w+) (?:and|or) (?<name2>\w+)/)
{
	say "I saw $+{name1} and $+{name2}";
}